package com.gem.day16;

import java.io.*;
import java.net.Socket;

/**客户端*/
public class ClientTCP {
	public static void main(String[] args) {
		BufferedInputStream bis = null;
		Socket socket = null;
		BufferedOutputStream bos = null;
		try {
			//创建流对象
			bis = new BufferedInputStream(new FileInputStream("D:\\object-orientation.pdf"));
			//创建输出流,写到服务器中
			socket = new Socket("localhost", 9999);
			bos = new BufferedOutputStream(socket.getOutputStream());
			//写出数据
			byte[] buf = new byte[10 * 1024];
			int len = -1;
			while ((len = bis.read(buf)) != -1) {
				bos.write(buf, 0, len);
				bos.flush();
			}
			System.out.println("文件发送完毕...");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				bis.close();
				bos.close();
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
